﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Eis51.CampanyCMS.Business.Bus;
using Eis51.CampanyCMS.Model.Bus;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.WebUI.Admin.Baseinfo
{
    public partial class MaintainList : BasePage
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            if (!IsPostBack)
            {
                btnSearch_Click(null, null);
            }
        }


        /// <summary>
        /// 查找
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, System.EventArgs e)
        {
            int isdo = int.Parse(drpDo.SelectedValue);
            DataTable dt = MaintainBLL.GetInstance().GetData(txtBeginDate.Text,txtEndDate.Text, isdo); ;
            dgNews.Data = dt;
            dgNews.DataBind();

        }

      

        protected void dgNews_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Delete":
                    Maintain obj =new  Maintain();
                    obj.Seqno = int.Parse(e.Item.Cells[0].Text);
                    MaintainBLL.GetInstance().Delete(obj);
                    this.btnSearch_Click(null, null);
                    break;
               
                case "D":
                    Maintain n1 = MaintainBLL.GetInstance().Get(new Maintain.Key(int.Parse(e.Item.Cells[0].Text)));
                    if (n1 != null)
                    {
                        n1.Isdo = n1.Isdo == 0 ? 1 : 0;
                        MaintainBLL.GetInstance().Update(n1);
                        this.btnSearch_Click(null, null);
                    }
                    break;
                default:
                    break;
            }
        }

        protected void dgNews_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {

            if (e.Item.ItemType == ListItemType.Header)
            {
                CheckBox cbxAll = e.Item.FindControl("cbxAll") as CheckBox;
                if (cbxAll != null)
                    cbxAll.Attributes.Add("onclick", "javascript:return SelectAll('" + dgNews.ClientID + "');");
            }
            if (e.Item.ItemType == ListItemType.AlternatingItem ||
                e.Item.ItemType == ListItemType.Item)
            {
                LinkButton btnDelete = e.Item.FindControl("btnDelete") as LinkButton;
             
                if (btnDelete != null)
                {


                    btnDelete.Attributes.Add("onclick", "javascript:return confirm('确定要删除吗?');");
                }

            }
        }

        public string ChangeCn(object ob)
        {
            if (ob != null)
            {
                if (ob.ToString() == "1")
                {
                    return "是";
                }
                else
                {
                    return "否";
                }
            }

            return "";

        }

        
    }
}
